package com.jiuqi.lr_demo.utils;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private String total;
    private T data;

    public static <T> Result<T> success (T data) {
        return Result.success (StatusCodeEnum.SC200.getMsg (), data);
    }

    public static <T> Result<T> success (String msg, T data) {
        Result<T> result = new Result<>();
        result.setCode (StatusCodeEnum.SC200.getCode ());
        result.setMsg (msg);
        result.setData (data);
        return result;
    }

    public static <T> Result<T> success (String msg, T data, String total) {
        Result<T> result = new Result<>();
        result.setCode (StatusCodeEnum.SC200.getCode ());
        result.setMsg (msg);
        result.setData (data);
        result.setTotal (total);
        return result;
    }

    public static <T> Result<T> fail (Integer code, String msg) {
        Result<T> result = new Result<>();
        result.setCode (code);
        result.setMsg (msg);
        return result;
    }

    public static <T> Result<T> fail (String msg) {
        Result<T> result = new Result<>();
        result.setMsg (msg);
        return result;
    }
}
